package io.renren.modules.cgs.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.cgs.entity.CgsReconsiderEntity;
import io.renren.modules.cgs.service.CgsReconsiderService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;


/**
 * 
 * 
 * @author wxy
 * @email sharonwang_xy@163.com
 * @date 2018-11-28 17:18:52
 */
@RestController
@RequestMapping("cgs/cgsreconsider")
public class CgsReconsiderController {
	@Autowired
	private CgsReconsiderService cgsReconsiderService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("cgs:cgsreconsider:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<CgsReconsiderEntity> cgsReconsiderList = cgsReconsiderService.queryList(query);
		int total = cgsReconsiderService.queryList(query.noLimit()).size();
		
		PageUtils pageUtil = new PageUtils(cgsReconsiderList, total, query.getLimit(), query.getCurrPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("cgs:cgsreconsider:info")
	public R info(@PathVariable("id") String id){
		CgsReconsiderEntity cgsReconsider = cgsReconsiderService.queryObject(id);
		
		return R.ok().put("cgsReconsider", cgsReconsider);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("cgs:cgsreconsider:save")
	public R save(@RequestBody CgsReconsiderEntity cgsReconsider){
		cgsReconsiderService.save(cgsReconsider);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
//	@RequestMapping("/update")
//	@RequiresPermissions("cgs:cgsreconsider:update")
//	public R update(@RequestBody CgsReconsiderEntity cgsReconsider){
//		cgsReconsiderService.update(cgsReconsider);
//
//		return R.ok();
//	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("cgs:cgsreconsider:delete")
	public R delete(@RequestBody String[] ids){
		cgsReconsiderService.deleteBatch(ids);
		
		return R.ok();
	}


	/**
	 * 修改审核
	 */
	@RequestMapping("/update/{id}")
	@RequiresPermissions("cgs:cgsreconsider:update")
	public R updateReconsiderInfo(@RequestBody Map<String,String> map){

		CgsReconsiderEntity cgsReconsider = cgsReconsiderService.queryObject(map.get("id"));
		cgsReconsider.setStatus(map.get("status"));
		cgsReconsider.setHandleTime(DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
		cgsReconsiderService.update(cgsReconsider);



		//发送信息

		return R.ok();
	}

}
